const axios = require('axios');
const logger = require('../utils/logger');

class CallbackService {
  // 通知推送结果
  static async notifyPushResult({ pushId, status, openid, contentLength, error, callbackUrl }) {
    try {
      const response = await axios.post(callbackUrl, {
        pushId,
        status,
        openid,
        contentLength,
        error,
        timestamp: new Date().toISOString()
      });

      if (response.status !== 200) {
        throw new Error(`回调失败: ${response.statusText}`);
      }

      logger.info('回调通知成功', {
        pushId,
        callbackUrl,
        status
      });
    } catch (err) {
      logger.error('回调通知失败', {
        pushId,
        callbackUrl,
        error: err.message
      });
      throw err;
    }
  }
}

module.exports = { CallbackService };